package com.realtest.baidu;

import java.util.Arrays;

/**
 * @Author: Ethan Yankang
 * @Program: Interview
 * @Date: 2024-08-24 23:05
 **/
public class MaxElement {
    public static void main(String[] args) {
//            int[] nums1=new int[]{3,4,6,5,4,5,2,6,8,2,8,26,8};
        int[] nums1=new int[]{3,4,6,5};
            System.out.println("原来的数组:");
            System.out.println(Arrays.toString(nums1));

            //Do Something
            solve(nums1,0,nums1.length);
            System.out.println("之后的数组:");
            System.out.println(Arrays.toString(nums1));
    }

    private static void solve(int[] nums1, int start, int end) {
            if (start==end-1) {
                nums1[start]=-1;
                return ;
            }
            if (maxNext(nums1,start+1,end)>nums1[start]){
                nums1[start]=minNext(nums1,start+1,end);
            }else {
                nums1[start]=-1;
            }
            solve(nums1,start+1,end);
    }

    private static int maxNext(int[] nums1,int start,int end) {
        int max=nums1[start];
        for (int i = start; i < end; i++) {
            max=Math.max(max,nums1[i]);
        }
        return max;
    }
    private static int minNext(int[] nums1,int start,int end) {
        int min=nums1[start];
        for (int i = start; i < end; i++) {
            min= Math.min(min,nums1[i]);
        }
        return min;
    }
}
